﻿/*
 * 文件名称：
 * 程序员：huangsb
 * 创建时间：2008/05/20
 * 
 * 功能说明：栏目操作权限管理
 * 
 * 修改人员：
 * 
 * 修改日期：
 * 
 * 修改记录：
 */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Whir.Common.WebHelper;

public partial class Whir_System_Module_Role_PageRole : System.Web.UI.Page
{
    protected string cid = "", rid = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        RoleHelper.IsLogin();    //登录判断
        if (RoleHelper.AdminCache.typeID != 1)
        {
            JsHelper.redirect(Page, "当前用户不是管理员，无法继续操作！", "../../Main.aspx");
        }

        this.cid = Whir.Common.WebHelper.NetRequest.SafeRequest(Page, "cid");
        this.rid = Whir.Common.WebHelper.NetRequest.SafeRequest(Page, "rid");

        if (!IsPostBack)
        {
            ViewState["RoleValue"] = "";
            ViewState["sort"] = "";
            setData();
        }
    }

    protected void setData()
    {
        DataTable dt = Whir.SQLServerDAL.DbHelperSQL.GetDataTable("roleName,roleValue,(select columnName from Whir_Column where columnID=" + this.cid + ") columnName","Whir_AdminRole", "roleID=" + this.rid,"");
        if (dt.Rows.Count > 0)
        {
            this.lbRoleName.Text = dt.Rows[0]["roleName"].ToString();
            this.lbColumnName.Text = dt.Rows[0]["columnName"].ToString();

            //设置权限
            int a = Whir.SQLServerDAL.Whir_Column.GetIDSort(int.Parse(this.cid));
            ViewState["sort"] = a.ToString();
            ViewState["RoleValue"] = dt.Rows[0]["roleValue"].ToString();

            if (a > 0)
            {
                string v1 = ViewState["RoleValue"].ToString().Substring((a - 1) * 8, 8);
                char[] vs = v1.ToCharArray();

                for (int i = 0; i <8; i++)
                {
                    if (vs[i] == '1')
                        this.cblRole.Items[7-i].Selected = true;
                    else
                        this.cblRole.Items[7-i].Selected = false;
                }
            }
        }
    }

    //提交
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Whir.SQLServerDAL.Whir_AdminRole bll = new Whir.SQLServerDAL.Whir_AdminRole();
        Whir.Model.Whir_AdminRole model = bll.GetModel(int.Parse(this.rid));

        model.updateDate = DateTime.Now;
        model.updateUserID = RoleHelper.GetAdminID();

        //权限值
        string v1 = "";
        for (int i = 7; i >= 0; i--)
        {
            if (this.cblRole.Items[i].Selected)
                v1 += "1";
            else
                v1 += "0";
        }

        string v = ViewState["RoleValue"].ToString();
        int a = int.Parse(ViewState["sort"].ToString());

        model.roleValue = v.Substring(0, (a - 1) * 8) + v1 + v.Substring(a * 8);

        bll.Update(model);

        Response.Redirect("ColumnRole.aspx?id=" + this.rid);
    }
}
